package com.geccocrawler.gecco.demo.hospital;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.JsonPipeline;
import com.geccocrawler.gecco.request.HttpPostRequest;
import com.geccocrawler.gecco.scheduler.DeriveSchedulerContext;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: weixiaohu
 * Date: 2019/6/3
 * Time: 15:05
 */
@PipelineName("areaPipeline")
public class AreaPipeline extends JsonPipeline {

    public static int areaCount;
    @Override
    public void process(JSONObject results) {
        JSONArray list = results.getJSONArray("list");
        areaCount = list.size();
        for (Object item : list) {
            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(item);
            HttpPostRequest subRequest = new HttpPostRequest("http://si.12333.gov.cn/118733/RemoteQuery003.jspx");
            Map<String,String> params = Maps.newHashMap();
            params.put("pageSize","1999");
            params.put("pageNo","1");
            params.put("provinceDesc",jsonObject.get("name",String.class));
            String province = jsonObject.get("id", String.class);
            params.put("province",province);
            params.put("aab299",province.substring(0,2));
            params.put("notkeyflag","1");
            subRequest.setFields(params);
            subRequest.setCharset("GBK");
            DeriveSchedulerContext.into(subRequest);
        }

    }

}
